package com.A21MobileSales;

import java.text.DecimalFormat;
import java.util.ArrayList;

import com.A21.Object.MSTProduct;
import com.A21.Object.MSTCustomerLocation;
import com.A21.Object.MSTSettings;
import com.A21MobileSales.R;
import com.A21MobileSales.DataBase.DatabaseHelper;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class ProductInfo extends Activity {

	DatabaseHelper ObjDBHelper;
	String Code;
	TextView tv_PName, tvCode, lblDetails, tvDetails, tvListPrice,
			tvRetailPrice, tvDealerPrice, tvPromotionPrice, tvLastSellingPrice,
			tvMinPrice, tvQty;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.product_info);

		try {

			if (getIntent().hasExtra("Code")) {
				Code = getIntent().getStringExtra("Code");
			}

			tvCode = (TextView) findViewById(R.id.tvCode);
			tv_PName = (TextView) findViewById(R.id.tv_PName);
			lblDetails = (TextView) findViewById(R.id.lblDetails);
			tvDetails = (TextView) findViewById(R.id.tvDetails);
			tvListPrice = (TextView) findViewById(R.id.tvListPrice);
			tvRetailPrice = (TextView) findViewById(R.id.tvRetailPrice);
			tvLastSellingPrice = (TextView) findViewById(R.id.tvLastSellingPrice);
			tvDealerPrice = (TextView) findViewById(R.id.tvDealerPrice);
			tvPromotionPrice = (TextView) findViewById(R.id.tvPromotionPrice);
			tvMinPrice = (TextView) findViewById(R.id.tvMinPrice);
			tvQty = (TextView) findViewById(R.id.tvQty);
			ObjDBHelper = new DatabaseHelper(this);
			MSTProduct product = ObjDBHelper.GetProductByCode(Code);
			tvCode.setText(Code); 
			if(product.DetailMemo==null)product.DetailMemo="";
			int noOfLines = countLines(product.DetailMemo)-1; 
			String strLblDetails = "Details";
			for (int l = 0; l < noOfLines; l++) {
				strLblDetails = strLblDetails + "\n ";
			}
			DecimalFormat df2 = new DecimalFormat("#0.00");

			tvCode.setText(product.Product);
			tv_PName.setText(product.PName);
			lblDetails.setText(strLblDetails);
			tvDetails.setText(product.DetailMemo);
			tvListPrice.setText(df2.format(product.ListPrice));
			tvRetailPrice.setText(df2.format(product.RetailPrice));
			tvLastSellingPrice.setText(df2.format(product.LastSellPrice));
			tvDealerPrice.setText(df2.format(product.DealerPrice));
			tvPromotionPrice.setText(df2.format(product.PromotionPrice));
			tvMinPrice.setText(df2.format(product.MinimumPrice));
			tvQty.setText(df2.format(product.OnHandQuantity));

		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}

	private static int countLines(String str) {
		String[] lines = str.split("\r\n|\r|\n");
		return lines.length;
	}

}